Skip to content

Resolve deprecation warnings related to datetime.utcnow in python 3.12#335

Open
brouberol wants to merge 2 commits into
mpdavis:masterfrom
brouberol:master
Open

Resolve deprecation warnings related to datetime.utcnow in python 3.12#335
brouberol wants to merge 2 commits into
mpdavis:masterfrom
brouberol:master

Conversation

@brouberol

@brouberol brouberol commented Nov 1, 2023

Copy link
Copy Markdown

When upgrading my project to python 3.12, I started seeing deprecation warnings related to the use of datetime.datetime.utcnow.

/Users/br/.../lib/python3.12/site-packages/jose/jwt.py:311: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
    now = timegm(datetime.utcnow().utctimetuple())

This PR simply implements the suggestion (in a backwards-compatible fashion), to get rid of these warnings in all projects depending on python-jose.

Regards

Fixes #334

@Jamim Jamim left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @brouberol,

Thank you for taking care of that warning!
I'd like to suggest a way to simplify your changes a bit.

Comment thread jose/utils.py Outdated
Comment thread jose/utils.py Outdated
Co-authored-by: Aliaksei Urbanski <aliaksei.urbanski@gmail.com>
@brouberol

Copy link
Copy Markdown
Author

Thanks @Jamim! Good call indeed

@phifuh

phifuh commented Jan 22, 2024

Copy link
Copy Markdown

will this be bundled into release 3.4 or just a minor update?

@Jamim

Jamim commented Jan 22, 2024

Copy link
Copy Markdown

Hello @phifuh,

will this be bundled into release 3.4 or just a minor update?

Sorry, but it looks like chances of this happening are near zero.

Best regards!

@phifuh

phifuh commented Jan 23, 2024

Copy link
Copy Markdown

@Jamim thats fair, eventually someone might fork this project and actively maintain it, at least thats what I hope

@spapanik

spapanik commented Feb 2, 2024

Copy link
Copy Markdown

@Jamim @phifuh I agree that there is a slim chance to get this change done, so I'm forking this, and I plan to create a successor for it. But, it seems like a lot of work to maintain multiple different backends, so I will keep cryptography and drop the rest.

@lsmith77

lsmith77 commented Feb 2, 2024

Copy link
Copy Markdown

guess it makes more sense to migrate to https://github.com/jpadilla/pyjwt

@asherf

asherf commented May 28, 2025

Copy link
Copy Markdown
Collaborator

fixed in #372

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deprecation warning from python 3.12

6 participants